//
//  ZhuanTDetailViewController.m
//  LT
//
//  Created by dllo on 16/5/21.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "ZhuanTDetailViewController.h"
#import "SetViewController.h"
#import <sqlite3.h>
#import "FMDB.h"
#import "DataBaseHandle.h"

@interface ZhuanTDetailViewController ()

@property(nonatomic,strong)SetViewController *setVC;

@property(nonatomic,strong)UIButton *rightButton;

//设置一个菜单按钮
@property(nonatomic,assign)BOOL isDisplyMenu;






@end

@implementation ZhuanTDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor whiteColor];
    UIWebView *webView = [[UIWebView alloc]initWithFrame:self.view.frame];
    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",self.ZhuanTString ]]]];
    [self.view addSubview:webView];
   
    //左按钮返回
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"goback"] style:UIBarButtonItemStylePlain target:self action:@selector(leftButtonAction)];
    
//    //setVC用作抽屉界面
    self.setVC = [[SetViewController alloc]init];
    self.setVC.view.frame = CGRectMake(500, 0, 100, 150);
    [self addChildViewController:self.setVC];
    [self.view addSubview:self.setVC.view];
    //右按钮收藏,或足迹,或想去
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"shoucang"] style:UIBarButtonItemStylePlain target:self action:@selector(rightButtonAction)];
//先默认菜单是关闭的
    self.isDisplyMenu = NO;
    
    
    //建立通知中心对象,给通知一个名字和一个点击方法
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(changHUD:) name:@"changHUD" object:nil];
   
}

//点击导航栏右侧按钮
-(void)rightButtonAction{

    NSLog(@"111");
    if (self.isDisplyMenu == NO) {
        //显示菜单
        
        [self show];
        
            NSLog(@"222");
    }else{
        [self hidden];
        NSLog(@"33");
    }
    
    self.isDisplyMenu = !self.isDisplyMenu;
    
}

#pragma mark -- 动画展开
-(void)show{
[UIView animateWithDuration:0.5 animations:^{
   
    
    self.setVC.view.frame = CGRectMake(300, 64, 80, 200);
    self.setVC.view.backgroundColor = [UIColor blueColor];
    self.setVC.view.alpha = 0.5;
    self.setVC.model = self.model;
    
    
    
}];

    

}

#pragma mark -- 动画收回
-(void)hidden{

[UIView animateWithDuration:0.5 animations:^{
    
    self.setVC.view.frame = CGRectMake(300, -136, 80, 200);
    self.setVC.view.backgroundColor = [UIColor blueColor];
    self.setVC.view.alpha = 0.5;
}];

    
}

//对应左按钮
-(void)leftButtonAction{
    [self.navigationController dismissViewControllerAnimated:YES  completion:^{
        
        
    }];
    
   
}

//在通知中心的点击方法中给一个参数,这个参数的目的是接受setVC传来的参数,然后对象不同的参数来进行判断,从而知道我们应该去执行哪个操作noti就是一个参数
-(void)changHUD:(NSNotification *)noti{
    
    NSString *compare = [noti object];
    //建立提示框对象,加载到view上,有动画显示
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    //提示框的模式
    hud.mode = MBProgressHUDModeCustomView;
    //提示框在0.5秒之后隐藏
    [hud hide:YES afterDelay:0.5];

    //如果收到setVC的传过来的参数为1,则提示收藏成功
    if ([compare isEqualToString:@"1"]) {
            hud.labelText = @"收藏成功";
    }else{
        //反之则已经收藏过,来取消收藏
            hud.labelText = @"取消收藏";
    }
    
    
    
    
}






- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
